﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;

namespace HuntTheWumpus
{
	class Cave
	{
		public struct Room
		{
			public int[] connections;
		}

		public Room[] rooms = new Room[30];

		public Cave() { }

		public void ReadCaveFile(int caveNumber)
		{
			TextReader tr;

			// Try to load the requested cave file. If the file doesn't exist, the 
			// user will be notified with a message box.
			try
			{
				tr = new StreamReader("cave" + caveNumber + ".txt");


					// This for loop system allows the class to assign room connections
					// to the 30 different rooms. There are 30 rooms in each cave, and
					// each room has six sides. Any sides that are walls are represented
					// by a "-1" in the cave file, and any walls will be calculated appropriately.
					for (int a = 0; a < 30; a++)
					{
						string input = tr.ReadLine();
						string[] data = input.Split(',');
						rooms[a].connections = new int[6];
						for (int b = 0; b < 6; b++)
						{
							int dataPoint = int.Parse(data[b]);
							if(dataPoint != -1){
								dataPoint--;
							}
							rooms[a].connections[b] = dataPoint;

						}
					}

				tr.Close();
			}
			catch
			{
				MessageBox.Show("Cave file not found. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}
	}
}
